#!/bin/bash -e

export XDG_RUNTIME_DIR=/tmp/nvim-gdb-runtime
export XDG_DATA_HOME=/tmp/nvim-gdb-runtime

export COLUMNS=$(tput cols)
export LINES=$(tput lines)

(
if [[ "$CI" ]]; then
    for i in $(seq 0 10); do
        timeout 0.1 bash -c 'cat </dev/null >/dev/tcp/localhost/44444' 2>/dev/null && break || true
    done
    python3 ./spy_ui.py
fi
) &

nvim -u NONE "+source init.vim" --listen localhost:44444 "$@"
ret=$?

kill %1
wait

exit $ret
